<template>
  <el-dialog :title="'详情'" :close-on-click-modal="false" :visible.sync="visible" fullscreen center append-to-body>
    <el-form class="verify-form" :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
      <el-row>
        <el-col :span="6">
          <el-form-item label="促销活动名称" prop="promotionTitle" label-width="100px">
            <el-input v-model="dataForm.promotionTitle" placeholder="促销活动名称" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="创建时间" prop="createTime">
            <el-input v-model="dataForm.createTime" placeholder="创建时间" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="生效时间" prop="startTime">
            <el-input v-model="dataForm.startTime" placeholder="生效时间" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="截至时间" prop="endTime">
            <el-input v-model="dataForm.endTime" placeholder="截至时间" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="备注" prop="memo">
        <el-input type="textarea" v-model="dataForm.memo" placeholder="备注" disabled></el-input>
      </el-form-item>

      <el-row>
        <el-col :span="24">
          <el-form-item label="查询部门">
            <el-input type="textarea" v-model="dataForm.deptName" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-tabs type="border-card">
        <el-tab-pane label="参与活动品种">
          <el-divider content-position="left">活动品种信息</el-divider>
          <div class="avue-crud">
            <el-table :data="this.dataForm.details" border @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column prop="ctgId" label="商品类别">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.ctgId" disabled>
                    <el-option v-for="item in ctgOption" :value="item.id" :label="item.name" :key="item.id"></el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column prop="saleCtgId" label="商品销售类别">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.saleCtgId" disabled>
                    <el-option v-for="item in saleCtgOption" :value="item.id" :label="item.name" :key="item.id"></el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column prop="supplyName" label="商品制造商" width="300"></el-table-column>
              <el-table-column prop="brandName" label="商品品种" width="300"></el-table-column>
              <el-table-column prop="spec" label="商品型号"></el-table-column>
              <el-table-column prop="originalPrice" label="该品种商品原价"></el-table-column>
              <el-table-column prop="promotionPrice" label="促销价格"></el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <search-dept v-if="deptVisible" ref="deptDialog" @refreshData="getDeptData"></search-dept>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { getEimsPromotionObj, } from '@/api/eims/promotion'
  import { getCtgList,getSaleCtgList, } from '@/api/eims/ctg'

  import { mapGetters } from 'Vuex'
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          promotionTitle: '',
          startTime: '',
          endTime: '',
          auditStatus: 0,
          auditUser: '',
          stopTime: '',
          stopUser: '',
          memo: '',
          deptName: '',
          depts: [],
          details: []
        },
        saleCtgOption: [],
        dataRule: {
          promotionTitle: [{
            required: true,
            message: '促销活动名称不能为空',
            trigger: 'blur'
          }],
          startTime: [{
            required: true,
            message: '生效时间不能为空',
            trigger: 'blur'
          }],
          endTime: [{
            required: true,
            message: '结束时间不能为空',
            trigger: 'blur'
          }],
          auditStatus: [{
            required: true,
            message: '审核状态(1-已审核,0-未审核)不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    created() {
      this.timeFormate(new Date());
      this.getCtgList();
      this.getSaleCtgList()
    },
    computed: {
      ...mapGetters(['userInfo', 'bizData'])
    },
    components: {
      
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        if (!this.dataForm.id) {
          this.timeFormate(new Date());
          this.dataForm.deptName = ''
          this.dataForm.depts = []
          this.dataForm.details = []
        }

        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getEimsPromotionObj(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
               this.dataForm = response.data.data
               this.dataForm.details = response.data.data.details
               this.dataForm.depts = response.data.data.depts
               let names = []
               this.dataForm.depts.forEach(item => {
                   names.push(item.deptName)
               })
               this.dataForm.deptName = names.join(',')
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      },
      //  获取商品类型列表
      getCtgList() {
        getCtgList().then(response => {
          if(response.data.code == '0'){
            this.ctgOption = response.data.data
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      getSaleCtgList(){
        getSaleCtgList().then(response => {
          if(response.data.code == '0'){
            this.saleCtgOption = response.data.data
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      //显示当前时间（年月日时分秒）
      timeFormate(timeStamp) {
        let year = new Date(timeStamp).getFullYear();
        let month = new Date(timeStamp).getMonth() + 1 < 10 ? "0" + (new Date(timeStamp).getMonth() + 1) : new Date(timeStamp).getMonth() + 1;
        let date = new Date(timeStamp).getDate() < 10 ? "0" + new Date(timeStamp).getDate() : new Date(timeStamp).getDate();
        let hh = new Date(timeStamp).getHours() < 10 ? "0" + new Date(timeStamp).getHours() : new Date(timeStamp).getHours();
        let mm = new Date(timeStamp).getMinutes() < 10 ? "0" + new Date(timeStamp).getMinutes() : new Date(timeStamp).getMinutes();
        let ss = new Date(timeStamp).getSeconds() < 10 ? "0" + new Date(timeStamp).getSeconds() : new Date(timeStamp).getSeconds();
        this.nowTime = "POUT" + year + "" + month + "" + date + "" + hh + "" + mm + "" + ss + this.dataForm.deptId;
        this.dataForm.createTime = year + "-" + month + "-" + date;
      },
    }
  }
</script>
